package MetroMessenger;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class MulticastSender implements Runnable
{   
   private byte[] messageBytes; 
   
   public MulticastSender( byte[] bytes ) 
   { 
      messageBytes = bytes; 
   }
   public void run() 
   {
      try 
      {         
         DatagramSocket socket = new DatagramSocket( SocketMessengerConstants.MULTICAST_SENDING_PORT );
         InetAddress group = InetAddress.getByName( SocketMessengerConstants.MULTICAST_ADDRESS );
         DatagramPacket packet = new DatagramPacket( messageBytes,messageBytes.length, group, SocketMessengerConstants.MULTICAST_LISTENING_PORT );
         socket.send( packet ); 
         socket.close(); 
      } 
      catch ( IOException ioException ) 
      { 
         ioException.printStackTrace();
      }
   }
}